#include "LocalCrossoverWorker.h"
#include "../../../Framework/Framework.h"

LocalCrossoverWorker::LocalCrossoverWorker()
{
}

void LocalCrossoverWorker::run()
{
    while (!haltRequested)
    {
        cJob = framework->getCrossoverJob(this);
        if (cJob == NULL)
        {
            ZThread::Thread::yield();
        }
        else
        {
            if (crossover == NULL)
                throw No_crossover_set_exception();

            Solution *child1;
            Solution *child2;
            crossover->cross(cJob->getParent1(), cJob->getParent2(), child1, child2);
                
            cJob->setChild1(child1);
            cJob->setChild2(child2);
                
            child1->mutate();
            child2->mutate();
                            
            framework->handleWorkerDone(this);
        }
    }
}
